package com.service.impl;

import com.dao.CityDAO;
import com.entity.City;
import com.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("cityService")
public class CityServiceImpl implements CityService {
    @Autowired
    private CityDAO cityDAO;
    @Override
    public Map selectAll(Integer offset, Integer limit) {
        List<City> list=cityDAO.selectAll(offset,limit);
        Integer count=cityDAO.selectCount();
        Map map=new HashMap();
        map.put("rows",list);
        map.put("total",count);
        return map;
    }

    @Override
    public City selectOne(Integer cityId) {
        return cityDAO.selectOne(cityId);
    }

    @Override
    public Map update(City city) {
        int count=cityDAO.update(city);
        Map map=new HashMap();
        if (count>0){
            map.put("isUpdate","修改成功");
        }else {
            map.put("isUpdate","修改失败");
        }
        return map;
    }

    @Override
    public void insert(City city) {
        cityDAO.insert(city);
    }
}
